package com.sy.simpleegg.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.sy.simpleegg.room.entity.OutEntity

@Dao
interface OutDao {
    @Query("SELECT * FROM tb_out")
    fun getAll(): List<OutEntity>?
    
    @Query("SELECT * FROM tb_out WHERE uuid = :uuid")
    fun getByUuidd(uuid: String): List<OutEntity>?

    @Query("UPDATE tb_out SET success = :state WHERE id = :id")
    fun updateStateById(id: Long, state: Int)

    @Query("UPDATE tb_out SET success = :state WHERE uuid = :uuid")
    fun updateStateByUuid(uuid: String, state: Int)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(outEntity: OutEntity)

    @Transaction
    fun insertAll(outEntities: List<OutEntity>){
        outEntities.forEach {
            insert(it)
        }
    }

    @Delete
    fun delete(outEntity: OutEntity)

    @Query("DELETE FROM tb_out")
    fun deleteAll()

    @Query("DELETE FROM tb_out where uuid = :uuid")
    fun deleteByUuid(uuid: String)

    @Query("DELETE FROM tb_out where id = :id")
    fun deleteById(id: Long)

}